﻿
Imports std

Public Module contentTypes
    Private _contentTypes As map(Of String, String) = Nothing

    Public Function contentTypes() As map(Of String, String)
        If _contentTypes Is Nothing Then
            initialContentTypes()
        End If
        Return _contentTypes
    End Function

    Public Function getdefaultContentType(ByVal filename As String) As String
        Dim suffix As String = Nothing
        'case insensitive for content type
        suffix = strtolower(filenamesuffix(filename))

        Dim it As map(Of String, String).iterator = Nothing
        it = contentTypes().find(suffix)
        If it = contentTypes().end Then
            Return network.http.contentType.applicationOctetStream
        Else
            Return (+it).second
        End If
    End Function

    Private Sub initialContentTypes()
        If _contentTypes Is Nothing Then
            _contentTypes = New map(Of String, String)
            SyncLock _contentTypes
                If _contentTypes.size() = 0 Then
                    _contentTypes("*") = "application/octet-stream"
                    _contentTypes("001") = "application/x-001"
                    _contentTypes("301") = "application/x-301"
                    _contentTypes("323") = "text/h323"
                    _contentTypes("7z") = "application/x-7z-compressed"
                    _contentTypes("906") = "application/x-906"
                    _contentTypes("907") = "drawing/907"
                    _contentTypes("a11") = "application/x-a11"
                    _contentTypes("acp") = "audio/x-mei-aac"
                    _contentTypes("ai") = "application/postscript"
                    _contentTypes("aif") = "audio/aiff"
                    _contentTypes("aifc") = "audio/aiff"
                    _contentTypes("aiff") = "audio/aiff"
                    _contentTypes("anv") = "application/x-anv"
                    _contentTypes("asa") = "text/asa"
                    _contentTypes("asf") = "video/x-ms-asf"
                    _contentTypes("asp") = "text/asp"
                    _contentTypes("asx") = "video/x-ms-asf"
                    _contentTypes("au") = "audio/basic"
                    _contentTypes("avi") = "video/avi"
                    _contentTypes("awf") = "application/vnd.adobe.workflow"
                    _contentTypes("biz") = "text/xml"
                    _contentTypes("bmp") = "application/x-bmp"
                    '_contentTypes("bmp") = "image/bmp"
                    _contentTypes("bot") = "application/x-bot"
                    _contentTypes("c4t") = "application/x-c4t"
                    _contentTypes("c90") = "application/x-c90"
                    _contentTypes("cal") = "application/x-cals"
                    _contentTypes("cat") = "application/vnd.ms-pki.seccat"
                    _contentTypes("cdf") = "application/x-netcdf"
                    _contentTypes("cdr") = "application/x-cdr"
                    _contentTypes("cel") = "application/x-cel"
                    _contentTypes("cer") = "application/x-x509-ca-cert"
                    _contentTypes("cg4") = "application/x-g4"
                    _contentTypes("cgm") = "application/x-cgm"
                    _contentTypes("cit") = "application/x-cit"
                    _contentTypes("class") = "java/*"
                    _contentTypes("cml") = "text/xml"
                    _contentTypes("cmp") = "application/x-cmp"
                    _contentTypes("cmx") = "application/x-cmx"
                    _contentTypes("cot") = "application/x-cot"
                    _contentTypes("crl") = "application/pkix-crl"
                    _contentTypes("crt") = "application/x-x509-ca-cert"
                    _contentTypes("csi") = "application/x-csi"
                    _contentTypes("css") = "text/css"
                    _contentTypes("cut") = "application/x-cut"
                    _contentTypes("dbf") = "application/x-dbf"
                    _contentTypes("dbm") = "application/x-dbm"
                    _contentTypes("dbx") = "application/x-dbx"
                    _contentTypes("dcd") = "text/xml"
                    _contentTypes("dcx") = "application/x-dcx"
                    _contentTypes("der") = "application/x-x509-ca-cert"
                    _contentTypes("dgn") = "application/x-dgn"
                    _contentTypes("dib") = "application/x-dib"
                    _contentTypes("dll") = "application/x-msdownload"
                    _contentTypes("doc") = "application/msword"
                    _contentTypes("dot") = "application/msword"
                    _contentTypes("drw") = "application/x-drw"
                    _contentTypes("dtd") = "text/xml"
                    '_contentTypes("dwf") = "Model/vnd.dwf"
                    _contentTypes("dwf") = "application/x-dwf"
                    _contentTypes("dwg") = "application/x-dwg"
                    _contentTypes("dxb") = "application/x-dxb"
                    _contentTypes("dxf") = "application/x-dxf"
                    _contentTypes("edn") = "application/vnd.adobe.edn"
                    _contentTypes("emf") = "application/x-emf"
                    _contentTypes("eml") = "message/rfc822"
                    _contentTypes("ent") = "text/xml"
                    _contentTypes("epi") = "application/x-epi"
                    '_contentTypes("eps") = "application/x-ps"
                    _contentTypes("eps") = "application/postscript"
                    _contentTypes("etd") = "application/x-ebx"
                    _contentTypes("exe") = "application/x-msdownload"
                    _contentTypes("fax") = "image/fax"
                    _contentTypes("fdf") = "application/vnd.fdf"
                    _contentTypes("fif") = "application/fractals"
                    _contentTypes("fo") = "text/xml"
                    _contentTypes("frm") = "application/x-frm"
                    _contentTypes("g4") = "application/x-g4"
                    _contentTypes("gbr") = "application/x-gbr"
                    _contentTypes("gcd") = "application/x-gcd"
                    _contentTypes("gif") = "image/gif"
                    _contentTypes("gl2") = "application/x-gl2"
                    _contentTypes("gp4") = "application/x-gp4"
                    _contentTypes("hgl") = "application/x-hgl"
                    _contentTypes("hmr") = "application/x-hmr"
                    _contentTypes("hpg") = "application/x-hpgl"
                    _contentTypes("hpl") = "application/x-hpl"
                    _contentTypes("hqx") = "application/mac-binhex40"
                    _contentTypes("hrf") = "application/x-hrf"
                    _contentTypes("hta") = "application/hta"
                    _contentTypes("htc") = "text/x-component"
                    _contentTypes("htm") = "text/html"
                    _contentTypes("html") = "text/html"
                    _contentTypes("htt") = "text/webviewhtml"
                    _contentTypes("htx") = "text/html"
                    _contentTypes("icb") = "application/x-icb"
                    _contentTypes("ico") = "image/x-icon"
                    '_contentTypes("ico") = "application/x-ico"
                    _contentTypes("iff") = "application/x-iff"
                    _contentTypes("ig4") = "application/x-g4"
                    _contentTypes("igs") = "application/x-igs"
                    _contentTypes("iii") = "application/x-iphone"
                    _contentTypes("img") = "application/x-img"
                    _contentTypes("ins") = "application/x-internet-signup"
                    _contentTypes("isp") = "application/x-internet-signup"
                    _contentTypes("IVF") = "video/x-ivf"
                    _contentTypes("java") = "java/*"
                    _contentTypes("jfif") = "image/jpeg"
                    _contentTypes("jpe") = "image/jpeg"
                    '_contentTypes("jpe") = "application/x-jpe"
                    _contentTypes("jpeg") = "image/jpeg"
                    _contentTypes("jpg") = "image/jpeg"
                    '_contentTypes("jpg") = "application/x-jpg"
                    _contentTypes("js") = "application/x-javascript"
                    _contentTypes("jsp") = "text/html"
                    _contentTypes("la1") = "audio/x-liquid-file"
                    _contentTypes("lar") = "application/x-laplayer-reg"
                    _contentTypes("latex") = "application/x-latex"
                    _contentTypes("lavs") = "audio/x-liquid-secure"
                    _contentTypes("lbm") = "application/x-lbm"
                    _contentTypes("lmsff") = "audio/x-la-lms"
                    _contentTypes("ls") = "application/x-javascript"
                    _contentTypes("ltr") = "application/x-ltr"
                    _contentTypes("m1v") = "video/x-mpeg"
                    _contentTypes("m2v") = "video/x-mpeg"
                    _contentTypes("m3u") = "audio/mpegurl"
                    _contentTypes("m4e") = "video/mpeg4"
                    _contentTypes("mac") = "application/x-mac"
                    _contentTypes("man") = "application/x-troff-man"
                    _contentTypes("math") = "text/xml"
                    '_contentTypes("mdb") = "application/msaccess"
                    _contentTypes("mdb") = "application/x-mdb"
                    _contentTypes("mfp") = "application/x-shockwave-flash"
                    _contentTypes("mht") = "message/rfc822"
                    _contentTypes("mhtml") = "message/rfc822"
                    _contentTypes("mi") = "application/x-mi"
                    _contentTypes("mid") = "audio/mid"
                    _contentTypes("midi") = "audio/mid"
                    _contentTypes("mil") = "application/x-mil"
                    _contentTypes("mml") = "text/xml"
                    _contentTypes("mnd") = "audio/x-musicnet-download"
                    _contentTypes("mns") = "audio/x-musicnet-stream"
                    _contentTypes("mocha") = "application/x-javascript"
                    _contentTypes("movie") = "video/x-sgi-movie"
                    _contentTypes("mp1") = "audio/mp1"
                    _contentTypes("mp2") = "audio/mp2"
                    _contentTypes("mp2v") = "video/mpeg"
                    _contentTypes("mp3") = "audio/mp3"
                    _contentTypes("mp4") = "video/mpeg4"
                    _contentTypes("mpa") = "video/x-mpg"
                    _contentTypes("mpd") = "application/vnd.ms-project"
                    _contentTypes("mpe") = "video/x-mpeg"
                    _contentTypes("mpeg") = "video/mpg"
                    _contentTypes("mpg") = "video/mpg"
                    _contentTypes("mpga") = "audio/rn-mpeg"
                    _contentTypes("mpp") = "application/vnd.ms-project"
                    _contentTypes("mps") = "video/x-mpeg"
                    _contentTypes("mpt") = "application/vnd.ms-project"
                    _contentTypes("mpv") = "video/mpg"
                    _contentTypes("mpv2") = "video/mpeg"
                    _contentTypes("mpw") = "application/vnd.ms-project"
                    _contentTypes("mpx") = "application/vnd.ms-project"
                    _contentTypes("mtx") = "text/xml"
                    _contentTypes("mxp") = "application/x-mmxp"
                    _contentTypes("net") = "image/pnetvue"
                    _contentTypes("nrf") = "application/x-nrf"
                    _contentTypes("nws") = "message/rfc822"
                    _contentTypes("odc") = "text/x-ms-odc"
                    _contentTypes("out") = "application/x-out"
                    _contentTypes("p10") = "application/pkcs10"
                    _contentTypes("p12") = "application/x-pkcs12"
                    _contentTypes("p7b") = "application/x-pkcs7-certificates"
                    _contentTypes("p7c") = "application/pkcs7-mime"
                    _contentTypes("p7m") = "application/pkcs7-mime"
                    _contentTypes("p7r") = "application/x-pkcs7-certreqresp"
                    _contentTypes("p7s") = "application/pkcs7-signature"
                    _contentTypes("pc5") = "application/x-pc5"
                    _contentTypes("pci") = "application/x-pci"
                    _contentTypes("pcl") = "application/x-pcl"
                    _contentTypes("pcx") = "application/x-pcx"
                    _contentTypes("pdf") = "application/pdf"
                    '_contentTypes("pdf") = "application/pdf"
                    _contentTypes("pdx") = "application/vnd.adobe.pdx"
                    _contentTypes("pfx") = "application/x-pkcs12"
                    _contentTypes("pgl") = "application/x-pgl"
                    _contentTypes("pic") = "application/x-pic"
                    _contentTypes("pko") = "application/vnd.ms-pki.pko"
                    _contentTypes("pl") = "application/x-perl"
                    _contentTypes("plg") = "text/html"
                    _contentTypes("pls") = "audio/scpls"
                    _contentTypes("plt") = "application/x-plt"
                    _contentTypes("png") = "image/png"
                    '_contentTypes("png") = "application/x-png"
                    _contentTypes("pot") = "application/vnd.ms-powerpoint"
                    _contentTypes("ppa") = "application/vnd.ms-powerpoint"
                    _contentTypes("ppm") = "application/x-ppm"
                    _contentTypes("pps") = "application/vnd.ms-powerpoint"
                    '_contentTypes("ppt") = "application/vnd.ms-powerpoint"
                    _contentTypes("ppt") = "application/x-ppt"
                    _contentTypes("pr") = "application/x-pr"
                    _contentTypes("prf") = "application/pics-rules"
                    _contentTypes("prn") = "application/x-prn"
                    _contentTypes("prt") = "application/x-prt"
                    _contentTypes("ps") = "application/x-ps"
                    '_contentTypes("ps") = "application/postscript"
                    _contentTypes("ptn") = "application/x-ptn"
                    _contentTypes("pwz") = "application/vnd.ms-powerpoint"
                    _contentTypes("r3t") = "text/vnd.rn-realtext3d"
                    _contentTypes("ra") = "audio/vnd.rn-realaudio"
                    _contentTypes("ram") = "audio/x-pn-realaudio"
                    _contentTypes("rar") = "application/x-rar-compressed"
                    _contentTypes("ras") = "application/x-ras"
                    _contentTypes("rat") = "application/rat-file"
                    _contentTypes("rdf") = "text/xml"
                    _contentTypes("rec") = "application/vnd.rn-recording"
                    _contentTypes("red") = "application/x-red"
                    _contentTypes("rgb") = "application/x-rgb"
                    _contentTypes("rjs") = "application/vnd.rn-realsystem-rjs"
                    _contentTypes("rjt") = "application/vnd.rn-realsystem-rjt"
                    _contentTypes("rlc") = "application/x-rlc"
                    _contentTypes("rle") = "application/x-rle"
                    _contentTypes("rm") = "application/vnd.rn-realmedia"
                    _contentTypes("rmf") = "application/vnd.adobe.rmf"
                    _contentTypes("rmi") = "audio/mid"
                    _contentTypes("rmj") = "application/vnd.rn-realsystem-rmj"
                    _contentTypes("rmm") = "audio/x-pn-realaudio"
                    _contentTypes("rmp") = "application/vnd.rn-rn_music_package"
                    _contentTypes("rms") = "application/vnd.rn-realmedia-secure"
                    _contentTypes("rmvb") = "application/vnd.rn-realmedia-vbr"
                    _contentTypes("rmx") = "application/vnd.rn-realsystem-rmx"
                    _contentTypes("rnx") = "application/vnd.rn-realplayer"
                    _contentTypes("rp") = "image/vnd.rn-realpix"
                    _contentTypes("rpm") = "audio/x-pn-realaudio-plugin"
                    _contentTypes("rsml") = "application/vnd.rn-rsml"
                    _contentTypes("rt") = "text/vnd.rn-realtext"
                    '_contentTypes("rtf") = "application/msword"
                    _contentTypes("rtf") = "application/x-rtf"
                    _contentTypes("rv") = "video/vnd.rn-realvideo"
                    _contentTypes("sam") = "application/x-sam"
                    _contentTypes("sat") = "application/x-sat"
                    _contentTypes("sdp") = "application/sdp"
                    _contentTypes("sdw") = "application/x-sdw"
                    _contentTypes("sit") = "application/x-stuffit"
                    _contentTypes("slb") = "application/x-slb"
                    _contentTypes("sld") = "application/x-sld"
                    _contentTypes("slk") = "drawing/x-slk"
                    _contentTypes("smi") = "application/smil"
                    _contentTypes("smil") = "application/smil"
                    _contentTypes("smk") = "application/x-smk"
                    _contentTypes("snd") = "audio/basic"
                    _contentTypes("sol") = "text/plain"
                    _contentTypes("sor") = "text/plain"
                    _contentTypes("spc") = "application/x-pkcs7-certificates"
                    _contentTypes("spl") = "application/futuresplash"
                    _contentTypes("spp") = "text/xml"
                    _contentTypes("ssm") = "application/streamingmedia"
                    _contentTypes("sst") = "application/vnd.ms-pki.certstore"
                    _contentTypes("stl") = "application/vnd.ms-pki.stl"
                    _contentTypes("stm") = "text/html"
                    _contentTypes("sty") = "application/x-sty"
                    _contentTypes("svg") = "text/xml"
                    _contentTypes("swf") = "application/x-shockwave-flash"
                    _contentTypes("tdf") = "application/x-tdf"
                    _contentTypes("tg4") = "application/x-tg4"
                    _contentTypes("tga") = "application/x-tga"
                    _contentTypes("tif") = "image/tiff"
                    '_contentTypes("tif") = "application/x-tif"
                    _contentTypes("tiff") = "image/tiff"
                    _contentTypes("tld") = "text/xml"
                    _contentTypes("top") = "drawing/x-top"
                    _contentTypes("torrent") = "application/x-bittorrent"
                    _contentTypes("tsd") = "text/xml"
                    _contentTypes("txt") = "text/plain"
                    _contentTypes("uin") = "application/x-icq"
                    _contentTypes("uls") = "text/iuls"
                    _contentTypes("vcf") = "text/x-vcard"
                    _contentTypes("vda") = "application/x-vda"
                    _contentTypes("vdx") = "application/vnd.visio"
                    _contentTypes("vml") = "text/xml"
                    _contentTypes("vpg") = "application/x-vpeg005"
                    '_contentTypes("vsd") = "application/vnd.visio"
                    _contentTypes("vsd") = "application/x-vsd"
                    _contentTypes("vss") = "application/vnd.visio"
                    '_contentTypes("vst") = "application/vnd.visio"
                    _contentTypes("vst") = "application/x-vst"
                    _contentTypes("vsw") = "application/vnd.visio"
                    _contentTypes("vsx") = "application/vnd.visio"
                    _contentTypes("vtx") = "application/vnd.visio"
                    _contentTypes("vxml") = "text/xml"
                    _contentTypes("wav") = "audio/wav"
                    _contentTypes("wax") = "audio/x-ms-wax"
                    _contentTypes("wb1") = "application/x-wb1"
                    _contentTypes("wb2") = "application/x-wb2"
                    _contentTypes("wb3") = "application/x-wb3"
                    _contentTypes("wbmp") = "image/vnd.wap.wbmp"
                    _contentTypes("wiz") = "application/msword"
                    _contentTypes("wk3") = "application/x-wk3"
                    _contentTypes("wk4") = "application/x-wk4"
                    _contentTypes("wkq") = "application/x-wkq"
                    _contentTypes("wks") = "application/x-wks"
                    _contentTypes("wm") = "video/x-ms-wm"
                    _contentTypes("wma") = "audio/x-ms-wma"
                    _contentTypes("wmd") = "application/x-ms-wmd"
                    _contentTypes("wmf") = "application/x-wmf"
                    _contentTypes("wml") = "text/vnd.wap.wml"
                    _contentTypes("wmv") = "video/x-ms-wmv"
                    _contentTypes("wmx") = "video/x-ms-wmx"
                    _contentTypes("wmz") = "application/x-ms-wmz"
                    _contentTypes("wp6") = "application/x-wp6"
                    _contentTypes("wpd") = "application/x-wpd"
                    _contentTypes("wpg") = "application/x-wpg"
                    _contentTypes("wpl") = "application/vnd.ms-wpl"
                    _contentTypes("wq1") = "application/x-wq1"
                    _contentTypes("wr1") = "application/x-wr1"
                    _contentTypes("wri") = "application/x-wri"
                    _contentTypes("wrk") = "application/x-wrk"
                    _contentTypes("ws") = "application/x-ws"
                    _contentTypes("ws2") = "application/x-ws"
                    _contentTypes("wsc") = "text/scriptlet"
                    _contentTypes("wsdl") = "text/xml"
                    _contentTypes("wvx") = "video/x-ms-wvx"
                    _contentTypes("xdp") = "application/vnd.adobe.xdp"
                    _contentTypes("xdr") = "text/xml"
                    _contentTypes("xfd") = "application/vnd.adobe.xfd"
                    _contentTypes("xfdf") = "application/vnd.adobe.xfdf"
                    _contentTypes("xhtml") = "text/html"
                    '_contentTypes("xls") = "application/vnd.ms-excel"
                    _contentTypes("xls") = "application/x-xls"
                    _contentTypes("xlw") = "application/x-xlw"
                    _contentTypes("xml") = "text/xml"
                    _contentTypes("xpl") = "audio/scpls"
                    _contentTypes("xq") = "text/xml"
                    _contentTypes("xql") = "text/xml"
                    _contentTypes("xquery") = "text/xml"
                    _contentTypes("xsd") = "text/xml"
                    _contentTypes("xsl") = "text/xml"
                    _contentTypes("xslt") = "text/xml"
                    _contentTypes("xwd") = "application/x-xwd"
                    _contentTypes("x_b") = "application/x-x_b"
                    _contentTypes("x_t") = "application/x-x_t"
                    _contentTypes("zip") = "application/x-zip-compressed"
                End If
            End SyncLock
        End If
    End Sub
End Module
